//
//  main.m
//  OC_06_循环遍历_排序
//
//  Created by wyx on 16/3/2.
//  Copyright © 2016年 Apon. All rights reserved.
//

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
#pragma mark - 知识点1. for 循环遍历.
   /*----------------------------------------------------------------------------*/
#pragma mark 1.1 数组遍历.
#if 0
    NSArray *arr = @[@"zhangsan",@"Tom",@"Lisi"];
    for (int i = 0; i < arr.count; i++) {
        NSString *string = [arr objectAtIndex:i];
        NSLog(@"%@",string);
    }
#endif
    /**
     * 练习:
     *
     * 使用for循环完成:
     * 定义一个数组, 包含5个字符串对象, 倒序取出数组中所有元素, 并存储到另一可变数组中。
     */
#if 0
    NSArray *arr1 = @[@"zhangsan",@"Tom",@"Lisi"];
    NSMutableArray *arr2 = [NSMutableArray array];
    for (long i = arr1.count-1; i >= 0; i--) {
        [arr2 addObject:[arr1 objectAtIndex:i]];
    }
    NSLog(@"%@",arr2);
    
#endif
#pragma mark 1.2 字典遍历.
    /**
     * 练习:
     *
     * 使用for循环完成:
     * 定义一个字典, 用于存储一个人的name, sex, age三个数据, 完成对其三个数据的输出。
     */
#if 0
    NSDictionary *dic = @{@"name":@"zhangsan",
                          @"sex":@"male",
                          @"age":@"20"
                          };
    //获取所有 Key
    NSArray *arrKeys = dic.allKeys;
    for (NSInteger i = 0; i < arrKeys.count; i++) {
        NSString *key = [arrKeys objectAtIndex:i];
        NSString *value = [dic objectForKey:key];
        NSLog(@"%@",value);
    }
#endif
#pragma mark 1.3 集合遍历.
    /*----------------------------------------------------------------------------*/
#pragma mark - 知识点2. NSEnumerator(枚举器) 遍历.
#pragma mark 2.1 数组正序枚举.
    //核心 API objectEnumerator
#if 0
    NSArray *arr1 = @[@"zhangsan",@"Tom",@"Lisi"];
    NSEnumerator *enumerator = [arr1 objectEnumerator];
    id value;
    while (value = [enumerator nextObject]) {
        NSLog(@"%@",value);
    }
    
#endif
#pragma mark 2.2 数组反向枚举.
#if 0
    //核心 API reverObjectEnum..
    NSArray *arr1 = @[@"zhangsan",@"Tom",@"Lisi"];
    NSEnumerator *enumerator = [arr1 reverseObjectEnumerator];
    id value;
    while (value = [enumerator nextObject]) {
        NSLog(@"%@",value);
    }
#endif
#pragma mark 2.3 字典枚举.
#if 0
    NSDictionary *dic = @{@"name":@"zhangsan",
                          @"sex":@"male",
                          @"age":@"20"
                          };
    //核心 API
    NSEnumerator *enume = [dic objectEnumerator];
    id value;
    while (value = [enume nextObject]) {
        NSLog(@"%@",value);
    }
#endif
#pragma mark 2.4 集合枚举.
    /*----------------------------------------------------------------------------*/
#pragma mark - 知识点3. !!! 重点 for...in 遍历.
    
#pragma mark 3.1 数组遍历.
#if 0
    NSArray *arr = @[@"zhangsan",@"Tom",@"Lisi"];
    for (NSString *string in arr) {
        NSLog(@"%@",string);
    }
#endif
    /**
     * 练习:
     *
     * 使用 for...in 完成:
     * 定义一个数组, 包含5个字符串对象, 取出数组中所有字符串, 并拼接生成一个新的字符串。
     */
#if 0
    NSArray *arr = @[@"zhangsan",@"Tom",@"Lisi",@"sffs",@"dsgs"];
    NSMutableString *mstr = [NSMutableString string];
    for (NSString *string in arr) {
        NSLog(@"%@",string);
        [mstr appendString:string];
    }
    NSLog(@"%@",mstr);
#endif
#pragma mark 3.2 字典遍历.
#if 0
    NSDictionary *dic = @{@"name":@"zhangsan",
                          @"sex":@"male",
                          @"age":@"20"
                          };
    //forin 对字典遍历时,遍历的是 Key
    for (NSString *key in dic) {
        NSString *value = [dic objectForKey:key];
        NSLog(@"value:%@",value);
    }
#endif
    /**
     * 练习:
     *
     * 使用 for...in... 完成:
     * 定义一个字典, 用于存储一个人的name, sex, age三个数据,  for...in...遍历, 输出此人的name到控制台
     */
#if 0
    NSDictionary *dic = @{@"name":@"zhangsan",
                          @"sex":@"male",
                          @"age":@"20"
                          };
    for (NSString *key in dic) {
        
        if ([key isEqualToString:@"name"]) {
            NSString *value = [dic objectForKey:key];
            NSLog(@"%@",value);
        }
    }
#endif
#pragma mark 3.3 集合遍历.
    /*----------------------------------------------------------------------------*/
#pragma mark - 知识点4. 数组排序.
    
#pragma mark 4.1 NSSortDescriptor
    
#pragma mark 4.2 selector
    /**
     * 练习:
     *
     * 生成一个包含5个Person对象的可变数组
     
     使用sortedArrayUsingSelector: 按姓名降序排序
     使用sortUsingSelector: 按年龄升序排序
     */
    return 0;
}
